<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        body{
            background-color: aliceblue;
        }
        .poemBox{
            display: flex;
        }
        .item{
            width: 300px;
            min-height: 200px;
            background-color: antiquewhite;
            border: 1px solid #f60;
            text-align: center;
            margin: 20px;
            
        }
        .author{
            font-size: 12px;
            color: gray;
        }
        button{
            margin-left: 20px;
        }
    </style>
</head>
<body>
    <button class="back">后退</button>
    <div class="poemBox">
        <!-- <div class="item">
            <h3>静夜思</h3>
            <p class="author">作者:李白</p>
            <p><span>床前明月光,</span><span>疑是地上霜。</span></p>
            <p><span>举头望明月,</span><span>低头思故乡。</span></p>
        </div> -->

    </div>
    <script>
        // 获取数据
        let poems = JSON.parse(localStorage.getItem('poems'))

        // 渲染数据 map + join
       let newPoems =  poems.map(function(item,index){
            item.tx = item.tx.split(',')  // 字符串 ---> 数组
            let content = ''
            for (let i = 0; i < item.tx.length; i++) {
                // 单数加逗号,偶数加句号
                if((i+1) % 2 === 0){  // (1)2 , (3)4 , (5)6 , (7)8      // 0+1  1+1
                    content += `<p><span>${item.tx[i-1]},</span><span>${item.tx[i]}。</span></p>`
                }
            }

            return `
                <div class="item">
                    <h3>${item.title}</h3>
                    <p class="author">作者:${item.author}</p>
                    ${content}
                </div>
            `
        })

        document.querySelector('.poemBox').innerHTML = newPoems.join('')
        
    </script>
</body>
</html> 